<?php
/**
 * Description of product
 *
 * @author joaoneto
 */
class product extends Baseproduct
{
	/**
	 * Save a new product from database or update one row
	 * @param array $params The params must be:
	 * <pre>
	 *	array(
	 *		'product' => array( ),
	 *		'tags' => array( ),
	 *	);
	 * </pre>
	 * @return product
	 * @throws Exception If product does not have saved
	 */
	public function saveProduct( array $params )
	{
		var_dump( $params );
		exit;
//		$productTagsModel = new productTag();
//		$productTagsModel->addTagToProduct( $this, $params[ 'tags' ] );

		$productDescModel = new productDesc();
		$productDescModel->addDescToProduct( $this, $params[ 'product' ], $params[ 'lang' ][ 'id_lang' ] );

		$productDescModel = new productMetainfo();
		$productDescModel->addMetainfoToProduct( $this, $params[ 'meta' ], $params[ 'lang' ][ 'id_lang' ] );

		$this->dt_product_create_date = date( 'c' );

		$this->_persistInstance( );

		exit;
	}

	/**
	 * Save the product to the Database
	 * @param  $product
	 * @return void
	 * @throws Doctrine_Exception
	 */
	private function _persistInstance( )
	{
		//created now
		return $this->save();
	}

	private function _test()
	{
		$product = new product();
		$product->dt_product_create_date = time();

		$desc = new productDesc();
		$desc->Translation[ 'pt_BR' ]->nm_product_name = 'Teste';
		$desc->Translation[ 'pt_BR' ]->nm_product_name_short = 'Teste';
		$desc->Translation[ 'pt_BR' ]->nm_product_name_sku = 'Teste';

		var_dump( $desc->toArray() );
		$desc->save();

		exit;
		$product->productDesc = $desc;

		$meta = new productMetainfo();
		$meta->save();
		$meta->Translation[ 'pt_BR' ]->nm_product_metakey= 'Teste';
		$meta->Translation[ 'pt_BR' ]->nm_product_metainfo = 'Teste';

		$meta->save();

		$product->productMetainfo = $meta;

		$product->save();

		exit;

	}
}